package com.woke.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bean.UserHeadColumn;
import com.bumptech.glide.Glide;
import com.netease.nim.uikit.GlideApp;
import com.zhongcai.online.R;

import me.drakeet.multitype.ItemViewProvider;


/**
 * 作者 ： 暗网
 * 创建时间：2017/2/17
 * 备注： 实名认证  上传图图片
 */

public class RealNameColumnViewProvider extends ItemViewProvider<UserHeadColumn, RealNameColumnViewProvider.ViewHolder> {

	private OnItemClickListener mItemClickListener;

	public RealNameColumnViewProvider(OnItemClickListener listener) {
		mItemClickListener = listener;
	}

	@NonNull
	@Override
	protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
		View itemView = inflater.inflate (R.layout.adapter_upload_pic, parent, false);
		return new ViewHolder (itemView);
	}

	@Override
	protected void onBindViewHolder(@NonNull final ViewHolder holder, @NonNull final UserHeadColumn headColumn) {

		holder.columnName.setText (headColumn.getColumnName ());
		if (headColumn.getIntent () == null) {
			holder.photoImg.setVisibility (View.INVISIBLE);
		} else {
			if (! TextUtils.isEmpty (headColumn.getDrawableUrl ())) {
				GlideApp.with (holder.itemView.getContext ())
						.load (headColumn.getDrawableUrl ())
						.placeholder(R.mipmap.icn__launch_oem)
						.error(R.mipmap.icn__launch_oem)
						.into (holder.photoImg);
			}
		}
		holder.itemView.setOnClickListener (new View.OnClickListener () {
			@Override
			public void onClick(View view) {
				if (mItemClickListener != null) {
					mItemClickListener.OnItemClick (view, headColumn, getPosition (holder));
				}
			}
		});
	}

	class ViewHolder extends RecyclerView.ViewHolder {

		private TextView columnName;
		private ImageView photoImg;

		public ViewHolder(View itemView) {
			super (itemView);
			columnName = (TextView) itemView.findViewById (R.id.columnName);
			photoImg = (ImageView) itemView.findViewById (R.id.upload_photo_img);
		}


	}
}
